<?php
/**
 * User.php
 * phpstorm_company_name_str - phpstorm_company_product_name
 * ***************************************************************************************************************************
 * 版权声明: Copyright ©2019 phpstorm_company_name_str All rights reserved
 * 官方网站: phpstorm_company_product_url
 * 许可声明: 这不是一个自由软件！您只能在购买源代码后或者经 phpstorm_company_name_str 官方授权的前提下对程序代码进行修改和使用，
 * 任何企业或个人都不得在源代码上以任何形式任何目的的再次发布和销售以及镜像或复制,包括但不限于已购买源代码和官方授权者。
 * 警 告  : 如若您或贵司未经正式购买渠道获得授权，请立即停止侵权行为，我们已经委派 phpstorm_company_auth_legal 作为我们侵权
 * 起诉的法律代表，还请您或贵司尊重商业版权以及劳动成果，自觉停止侵权行为。您也可匿名举报侵权行为，一旦您的举报被证实，我们
 * 将会以本版本零售价的 phpstorm_company_product_percent_money% 现金给您，以便作为您的辛苦奖励。同时，我们也将竭尽全力保证您的隐私安全。举报邮箱: phpstorm_company_product_report_mail
 * 协议约定: 本产品遵守 << phpstorm_company_product_protocol >> 的约束,您或贵司也可以访问 phpstorm_company_product_protocol 了解更多详情信息。
 * 致 谢  : 感谢您或贵司对我们产品的支持和热爱，我们将不定期对本产品进行更新和修复bug。还请您和贵司多多指导。更多问题资讯请访问
 * phpstorm_company_product_help_url ,如果您正在对此版本进行二次开发，提bug或者需求可以发送到@author邮箱,或者提交工单。
 * 工单地址是: phpstorm_company_product_ticket_url 我们将尽快为您提出合理的解决方案。
 * 其 他  : 您或贵司也可以登录 phpstorm_company_product_doc_url 查看相关的文档资料以及FAQ！
 * ***************************************************************************************************************************
 * @product ctmoncms
 * @desc
 * @author justary <justary@126.com>
 * @date 2024/06/24 12:51
 * @version phpstorm_company_product_version
 * @copyright phpstorm_company_product_copyright
 */

/**
 * @package app\v1\controller
 *
 * @filesource User.php
 * @author justary <justary@126.com>
 * @date 2024/06/24 12:51
 * @link phpstorm_product_licence
 * @version phpstorm_company_product_version
 * @copyright phpstorm_company_product_copyright
 */


namespace app\v1\controller;


use app\data\logic\PageLogic;
use app\v1\BaseController;
use think\App;
use think\Request;

/**
 * @OA\Tag(
 *   name="user",
 *   description="用户管理"
 * )
 */
class CmsCat extends BaseController
{
    protected PageLogic $logic;

    public function __construct(App $app)
    {
        $this->logic = new PageLogic();
        parent::__construct($app);
    }

    /**
     *
     * @OA\Get(
     *     path="/friend/getFriendList",
     *     summary="获取好友列表",
     *     description="获取好友列表描述",
     *     operationId="getFriendList",
     *     tags={"friend"},
     *     @OA\Parameter(
     *         name="Accept-Language",
     *         in="header",
     *         description="i18n support",
     *         required=false,
     *         allowEmptyValue=true,
     *         @OA\Schema(
     *             type="string",
     *             example="zh-cn"
     *         )
     *     ),
     *     @OA\Response(
     *          response=200,
     *          description="show success status",
     *          @OA\MediaType(
     *              mediaType="application/json",
     *              @OA\Schema(ref="#/components/schemas/Success")
     *          )
     *     )
     * )
     */
    public function index()
    {

        $params = $this->request->param();
        $result = $this->logic->getCmsCatList($params);
        $list = array_key_exists('all', $params) ? $result : $result['list'];
        $count = array_key_exists('all', $params) ? $this->logic->getCmsCatCount() : $result['count'];
        if ($result) {
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'), $list, $count);
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }

    /**
     *
     * @OA\Post(
     *     path="/friend/addFriend",
     *     summary="新增好友",
     *     description="新增好友描述",
     *     operationId="addFriend",
     *     tags={"friend"},
     *     @OA\Parameter(
     *         name="Accept-Language",
     *         in="header",
     *         description="i18n support",
     *         required=false,
     *         allowEmptyValue=true,
     *         @OA\Schema(
     *             type="string",
     *             example="zh-cn"
     *         )
     *     ),
     *     @OA\RequestBody(
     *          description="user post add",
     *          @OA\MediaType(
     *                  mediaType="application/json",
     *                  @OA\Schema(ref="#/components/schemas/friendData")
     *         )
     *      ),
     *     @OA\Response(
     *          response=200,
     *          description="show success status",
     *          @OA\MediaType(
     *              mediaType="application/json",
     *              @OA\Schema(ref="#/components/schemas/Success")
     *          )
     *     )
     * )
     * @OA\Schema(
     *     schema="friendData",
     *     type="object",
     *     @OA\Property(
     *         property="id",
     *         type="integer",
     *         format="int64",
     *         example=1,
     *         description="好友id"
     *     ),
     *     @OA\Property(
     *         property="user_name",
     *         type="string",
     *         example="nike",
     *         description="好友名称"
     *     ),
     *     @OA\Property(
     *         property="nick_name",
     *         type="string",
     *         example="一个小刀",
     *         description="好友昵称"
     *     ),
     *     @OA\Property(
     *         property="create_time",
     *         type="string",
     *         example="2022-11-07 11:33:22",
     *         description="添加时间"
     *     ),
     *     @OA\Property(
     *         property="is_black",
     *         type="number",
     *         example=0,
     *         description="是否在黑名单，0：在，1：不在"
     *     ),
     *     @OA\Property(
     *         property="is_visit",
     *         type="number",
     *         example=1,
     *         description="是否允许访问空间,0：不允许，1：允许"
     *     )
     * )
     *
     */
    public function create()
    {
        //
        echo 'create';
    }

    /**
     *
     * @OA\Post(
     *     path="/friend/addFriend",
     *     summary="新增好友",
     *     description="新增好友描述",
     *     operationId="addFriend",
     *     tags={"friend"},
     *     @OA\Parameter(
     *         name="Accept-Language",
     *         in="header",
     *         description="i18n support",
     *         required=false,
     *         allowEmptyValue=true,
     *         @OA\Schema(
     *             type="string",
     *             example="zh-cn"
     *         )
     *     ),
     *     @OA\RequestBody(
     *          description="user post add",
     *          @OA\MediaType(
     *                  mediaType="application/json",
     *                  @OA\Schema(ref="#/components/schemas/friendData")
     *         )
     *      ),
     *     @OA\Response(
     *          response=200,
     *          description="show success status",
     *          @OA\MediaType(
     *              mediaType="application/json",
     *              @OA\Schema(ref="#/components/schemas/Success")
     *          )
     *     )
     * )
     * @OA\Schema(
     *     schema="friendData",
     *     type="object",
     *     @OA\Property(
     *         property="id",
     *         type="integer",
     *         format="int64",
     *         example=1,
     *         description="好友id"
     *     ),
     *     @OA\Property(
     *         property="user_name",
     *         type="string",
     *         example="nike",
     *         description="好友名称"
     *     ),
     *     @OA\Property(
     *         property="nick_name",
     *         type="string",
     *         example="一个小刀",
     *         description="好友昵称"
     *     ),
     *     @OA\Property(
     *         property="create_time",
     *         type="string",
     *         example="2022-11-07 11:33:22",
     *         description="添加时间"
     *     ),
     *     @OA\Property(
     *         property="is_black",
     *         type="number",
     *         example=0,
     *         description="是否在黑名单，0：在，1：不在"
     *     ),
     *     @OA\Property(
     *         property="is_visit",
     *         type="number",
     *         example=1,
     *         description="是否允许访问空间,0：不允许，1：允许"
     *     )
     * )
     *
     */
    public function save(Request $request)
    {
        $param = $request->param();
        $result = $this->logic->createCmsCat($param);
        if ($result['state']) {
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'));
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }

    /**
     *
     * @OA\Get(
     *     path="/friend/getFriendDetail",
     *     summary="获取好友详情",
     *     description="获取好友详情描述",
     *     operationId="getFriendDetail",
     *     tags={"friend"},
     *     @OA\Parameter(
     *         name="Accept-Language",
     *         in="header",
     *         description="i18n support",
     *         required=false,
     *         allowEmptyValue=true,
     *         @OA\Schema(
     *             type="string",
     *             example="zh-cn"
     *         )
     *     ),
     *     @OA\Parameter(
     *         name="id",
     *         in="query",
     *         description="id info",
     *         required=true,
     *         deprecated=false,
     *         allowEmptyValue=false,
     *         explode=false,
     *         allowReserved=false,
     *         example=1,
     *         @OA\Schema(
     *             type="number",
     *             example=1
     *         )
     *     ),
     *     @OA\Response(
     *          response=200,
     *          description="show success status",
     *          @OA\MediaType(
     *              mediaType="application/json",
     *              @OA\Schema(ref="#/components/schemas/Success")
     *          )
     *     ),
     *     security={
     *         {"petstore_auth": {"write:pets", "read:pets"}}
     *     },
     * )
     */
    public function read($id)
    {
        $result = $this->logic->getCmsCatDetail($id);
        if ($result['state']) {
            $partContent = $this->logic->getCmsList(['cat_id' => $result['data']['cat_id']]);
            $result['data']['cmsList'] = $partContent;
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'), $result['data']);
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }

    /**
     *
     * @OA\Put(
     *     path="/friend/editFriendInfo",
     *     summary="编辑好友信息",
     *     description="编辑好友信息描述",
     *     operationId="editFriendInfo",
     *     tags={"friend"},
     *     @OA\Parameter(
     *         name="Accept-Language",
     *         in="header",
     *         description="i18n support",
     *         required=false,
     *         allowEmptyValue=true,
     *         @OA\Schema(
     *             type="string",
     *             example="zh-cn"
     *         )
     *     ),
     *     @OA\RequestBody(
     *          description="user info edit",
     *          @OA\MediaType(
     *                  mediaType="application/json",
     *                  @OA\Schema(ref="#/components/schemas/friendIdParam")
     *         )
     *      ),
     *     @OA\Response(
     *          response=200,
     *          description="show success status",
     *          @OA\MediaType(
     *              mediaType="application/json",
     *              @OA\Schema(ref="#/components/schemas/Success")
     *          )
     *     )
     * )
     * @OA\Schema(
     *     schema="friendIdParam",
     *     type="object",
     *     @OA\Property(
     *         property="id",
     *         type="integer",
     *         format="int64",
     *         example=1,
     *         description="好友id"
     *     )
     * )
     *
     */
    public function edit($id)
    {
        //
        echo 'edit';
    }

    /**
     *
     * @OA\Put(
     *     path="/friend/editFriendInfo",
     *     summary="编辑好友信息",
     *     description="编辑好友信息描述",
     *     operationId="editFriendInfo",
     *     tags={"friend"},
     *     @OA\Parameter(
     *         name="Accept-Language",
     *         in="header",
     *         description="i18n support",
     *         required=false,
     *         allowEmptyValue=true,
     *         @OA\Schema(
     *             type="string",
     *             example="zh-cn"
     *         )
     *     ),
     *     @OA\RequestBody(
     *          description="user info edit",
     *          @OA\MediaType(
     *                  mediaType="application/json",
     *                  @OA\Schema(ref="#/components/schemas/friendIdParam")
     *         )
     *      ),
     *     @OA\Response(
     *          response=200,
     *          description="show success status",
     *          @OA\MediaType(
     *              mediaType="application/json",
     *              @OA\Schema(ref="#/components/schemas/Success")
     *          )
     *     )
     * )
     * @OA\Schema(
     *     schema="friendIdParam",
     *     type="object",
     *     @OA\Property(
     *         property="id",
     *         type="integer",
     *         format="int64",
     *         example=1,
     *         description="好友id"
     *     )
     * )
     *
     */
    public function update(Request $request, $id)
    {
        //
        $param = $request->param();
        if ($param['id']) {
            unset($param['id']);
        }

        $checkData['id'] = $id;
        $result = $this->logic->updateCmsCat($id, $param, $checkData);
        if ($result['state']) {
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'));
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }

    /**
     *
     * @OA\Delete(
     *     path="/friend/delFriend",
     *     summary="删除好友",
     *     description="删除好友描述",
     *     operationId="delFriend",
     *     tags={"friend"},
     *     @OA\Parameter(
     *         name="Accept-Language",
     *         in="header",
     *         description="i18n support",
     *         required=false,
     *         allowEmptyValue=true,
     *         @OA\Schema(
     *             type="string",
     *             example="zh-cn"
     *         )
     *     ),
     *     @OA\RequestBody(
     *          description="user info delete",
     *          @OA\MediaType(
     *                  mediaType="application/json",
     *                  @OA\Schema(ref="#/components/schemas/friendIdParam")
     *         )
     *      ),
     *     @OA\Response(
     *          response=200,
     *          description="show success status",
     *          @OA\MediaType(
     *              mediaType="application/json",
     *              @OA\Schema(ref="#/components/schemas/Success")
     *          )
     *     ),
     *     security={
     *         {"api_key": {}}
     *     },
     *     security={
     *         {"lang": {}}
     *     }
     * )
     */
    public function delete($id)
    {

        $result = $this->logic->deleteCmsCat($id);
        if ($result['state']) {
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'));
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }
}
